package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/6.
 */
@HttpInlet(Conn.INDEX_GET)
public class HomeGet extends BaseAsyGet<HomeGet.HomeEntity> {

    public String user_id, region_id;

    public HomeGet(AsyCallBack<HomeEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected HomeEntity parser(JSONObject object) throws Exception {

        if (object.optInt("code") == 200) {

            HomeEntity homeEntity = new HomeEntity();

            JSONObject jsonObject_main = object.optJSONObject("data");
            homeEntity.services_tel = jsonObject_main.optString("services_tel");
            homeEntity.purchase_booking = jsonObject_main.optString("purchase_booking");
            homeEntity.services_nosit_tel = jsonObject_main.optString("services_nosit_tel");
            homeEntity.backdrop = jsonObject_main.optString("backdrop");

            JSONArray jsonArray_banner = jsonObject_main.optJSONArray("banner");
            for (int i = 0; i < jsonArray_banner.length(); i++) {

                JSONObject jsonObject = jsonArray_banner.optJSONObject(i);
                HomeBannerEntity homeBannerEntity = new HomeBannerEntity();
                homeBannerEntity.id = jsonObject.optString("id");
                homeBannerEntity.title = jsonObject.optString("title");
                homeBannerEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");
                homeBannerEntity.type = jsonObject.optString("type");
                homeBannerEntity.good_id = jsonObject.optString("good_id");
                homeBannerEntity.url = jsonObject.optString("url");

                homeEntity.banner.add(homeBannerEntity);

            }

            JSONArray jsonArray_classify = jsonObject_main.optJSONArray("classify");
            for (int i = 0; i < jsonArray_classify.length(); i++) {

                JSONObject jsonObject = jsonArray_classify.optJSONObject(i);
                HomeClassifyEntity homeClassifyEntity = new HomeClassifyEntity();
                homeClassifyEntity.id = jsonObject.optString("id");
                homeClassifyEntity.title = jsonObject.optString("title");
                homeClassifyEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");

                homeEntity.classify.add(homeClassifyEntity);

            }

            JSONArray jsonArray_toplist = jsonObject_main.optJSONArray("toplist");
            for (int i = 0; i < jsonArray_toplist.length(); i++) {

                JSONObject jsonObject = jsonArray_toplist.optJSONObject(i);
                HomeToplistEntity homeToplistEntity = new HomeToplistEntity();
                homeToplistEntity.id = jsonObject.optString("id");
                homeToplistEntity.title = jsonObject.optString("title");
                homeEntity.toplist.add(homeToplistEntity);

            }

            JSONArray jsonArray_advertisement = jsonObject_main.optJSONArray("advertisement");
            for (int i = 0; i < jsonArray_advertisement.length(); i++) {

                JSONObject jsonObject = jsonArray_advertisement.optJSONObject(i);
                HomeAdvertisementEntity homeAdvertisementEntity = new HomeAdvertisementEntity();
                homeAdvertisementEntity.id = jsonObject.optString("id");
                homeAdvertisementEntity.title = jsonObject.optString("title");
                homeAdvertisementEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");
                homeAdvertisementEntity.type = jsonObject.optString("type");
                homeAdvertisementEntity.good_id = jsonObject.optString("good_id");
                homeAdvertisementEntity.icon = Conn.IMAGE_BANNER_URL + jsonObject.optString("icon");

                homeEntity.advertisement.add(homeAdvertisementEntity);

            }


            try {

                JSONObject object1 = jsonObject_main.optJSONObject("window");
                homeEntity.window.id = object1.optString("id");
                homeEntity.window.url = object1.optString("url");
                homeEntity.window.picurl = object1.optString("picurl");
                homeEntity.window.title = object1.optString("title");
            } catch (Exception e) {
                e.getMessage();
            }


            JSONArray jsonArray_show_list = jsonObject_main.optJSONArray("show_list");
            for (int i = 0; i < jsonArray_show_list.length(); i++) {
                JSONObject jsonObject = jsonArray_show_list.optJSONObject(i);
                HomeShowListEntity homeShowListEntity = new HomeShowListEntity();
                homeShowListEntity.id = jsonObject.optString("id");
                homeShowListEntity.title = jsonObject.optString("title");
                homeShowListEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");
                homeShowListEntity.start_time = jsonObject.optString("start_time");
                homeShowListEntity.status = jsonObject.optString("status");

                homeEntity.show_list.add(homeShowListEntity);

            }

            JSONArray jsonArray_GuessYouLike = jsonObject_main.optJSONArray("GuessYouLike");
            for (int i = 0; i < jsonArray_GuessYouLike.length(); i++) {

                JSONObject jsonObject = jsonArray_GuessYouLike.optJSONObject(i);
                HomeGuessYouLikeEntity homeGuessYouLikeEntity = new HomeGuessYouLikeEntity();
                homeGuessYouLikeEntity.id = jsonObject.optString("id");
                homeGuessYouLikeEntity.title = jsonObject.optString("title");
                homeGuessYouLikeEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");
                homeGuessYouLikeEntity.start_time = jsonObject.optString("start_time");
                homeGuessYouLikeEntity.placeid = jsonObject.optString("placeid");
                homeGuessYouLikeEntity.place_name = jsonObject.optString("place_name");
                homeGuessYouLikeEntity.is_seat = jsonObject.optString("is_seat");
                homeGuessYouLikeEntity.status = jsonObject.optString("status");

                homeEntity.GuessYouLike.add(homeGuessYouLikeEntity);

            }





        /*    JSONArray jsonArray_Classify = jsonObject_main.optJSONArray("classify");
            for(int i=0;i<jsonArray_Classify.length();i++){

                JSONObject jsonObject = jsonArray_Classify.optJSONObject(i);

                Classify homeGuessYouLikeEntity = new Classify();
                homeGuessYouLikeEntity.id = jsonObject.optString("id");
                homeGuessYouLikeEntity.title = jsonObject.optString("title");
                homeGuessYouLikeEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");


                homeEntity.classify.add(homeGuessYouLikeEntity);

            }
*/


            return homeEntity;

        }

        TOAST = object.optString("message");

        return null;
    }


    public static class HomeEntity {

        public String backdrop;
        public String services_tel;
        public String purchase_booking;
        public String services_nosit_tel;
        public List<HomeBannerEntity> banner = new ArrayList<>();
        public List<HomeClassifyEntity> classify = new ArrayList<>();
        public List<HomeToplistEntity> toplist = new ArrayList<>();
        public List<HomeAdvertisementEntity> advertisement = new ArrayList<>();
        public List<HomeShowListEntity> show_list = new ArrayList<>();
        public List<HomeGuessYouLikeEntity> GuessYouLike = new ArrayList<>();

        // public List<Classify> classify=new ArrayList<>();

        public Windows window = new Windows();


    }

    public static class Classify {
        public String id;
        public String title;
        public String picurl;
    }


    public static class HomeBannerEntity {

        public String id, title, picurl, type, good_id, url;

    }

    public static class HomeClassifyEntity {

        public String id, title, picurl;

    }

    public static class HomeToplistEntity {

        public String id, title;

    }

    public static class HomeAdvertisementEntity {

        public String id, title, picurl, type, good_id, icon;

    }

    public static class HomeShowListEntity {

        public String id, title, picurl, start_time, status;

    }

    public static class HomeGuessYouLikeEntity {

        public String id, title, picurl, start_time, placeid, place_name, is_seat, status;

    }


    public static class Windows implements Serializable {


        public String id, picurl, url, title;

    }


}
